const { default: axios } = require('axios')
const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
})

exports.main = async (event, context) => {
  try {
    // const res = await axios.get('https://api.beatsaver.com/maps/latest')
    let {id} = event;
    let url = 'https://beatsaver.com/api/maps/id/' + id
    const res = await axios.get(url)
    return {
      status: 'OK',
      data: res.data
    }
  } catch(err){
    return {
      status: 'ERROR',
      error: err.message | 'Request failed!'
    }
  }
}